const Has = require('../template')

console.log("=== Has 基础测试 ===")

// 测试基本属性存在性检查
console.log(
  "基本属性存在性检查:", (() => {
    const obj = { a: 1, b: 2, c: 3 }

    return Has.has(obj, 'a') === true &&
      Has.has(obj, 'b') === true &&
      Has.has(obj, 'c') === true &&
      Has.has(obj, 'd') === false
  })()
)

// 测试嵌套属性存在性检查
console.log(
  "嵌套属性存在性检查:", (() => {
    const obj = { a: { b: { c: 42 } } }

    return Has.has(obj, 'a') === true &&
      Has.has(obj, 'a.b') === true &&
      Has.has(obj, 'a.b.c') === true &&
      Has.has(obj, 'a.b.d') === false &&
      Has.has(obj, 'a.c') === false &&
      Has.has(obj, 'b') === false
  })()
)

// 测试数组索引存在性检查
console.log(
  "数组索引存在性检查:", (() => {
    const obj = { users: [{ name: 'Alice' }, { name: 'Bob' }] }

    return Has.has(obj, 'users') === true &&
      Has.has(obj, 'users.0') === true &&
      Has.has(obj, 'users.0.name') === true &&
      Has.has(obj, 'users.1') === true &&
      Has.has(obj, 'users.1.name') === true &&
      Has.has(obj, 'users.2') === false &&
      Has.has(obj, 'users.0.age') === false
  })()
)

// 测试不存在的属性检查
console.log(
  "不存在的属性检查:", (() => {
    const obj = { a: 1 }

    return Has.has(obj, 'b') === false &&
      Has.has(obj, 'c.d.e') === false &&
      Has.has(obj, 'nonexistent') === false
  })()
)

// 测试数组路径存在性检查
console.log(
  "数组路径存在性检查:", (() => {
    const obj = { data: { items: [1, 2, 3] } }
    const path = ['data', 'items', '0']

    return Has.has(obj, path) === true &&
      Has.has(obj, ['data', 'items', '1']) === true &&
      Has.has(obj, ['data', 'items', '2']) === true &&
      Has.has(obj, ['data', 'items', '3']) === false &&
      Has.has(obj, ['data', 'nonexistent']) === false
  })()
)

// 测试空对象存在性检查
console.log(
  "空对象存在性检查:", (() => {
    const obj = {}

    return Has.has(obj, 'any.path') === false &&
      Has.has(obj, 'nonexistent') === false
  })()
)

// 测试null对象存在性检查
console.log(
  "null对象存在性检查:", (() => {
    const obj = null

    return Has.has(obj, 'any.path') === false &&
      Has.has(obj, 'nonexistent') === false
  })()
)

// 测试undefined对象存在性检查
console.log(
  "undefined对象存在性检查:", (() => {
    const obj = undefined

    return Has.has(obj, 'any.path') === false &&
      Has.has(obj, 'nonexistent') === false
  })()
)

// 测试复杂嵌套结构存在性检查
console.log(
  "复杂嵌套结构存在性检查:", (() => {
    const obj = {
      user: {
        profile: {
          personal: {
            name: 'John',
            age: 30,
            address: {
              city: 'New York',
              country: 'USA'
            }
          },
          preferences: {
            theme: 'dark',
            language: 'en'
          }
        },
        posts: [
          { title: 'Post 1', likes: 10 },
          { title: 'Post 2', likes: 20 }
        ]
      }
    }

    return Has.has(obj, 'user') === true &&
      Has.has(obj, 'user.profile') === true &&
      Has.has(obj, 'user.profile.personal') === true &&
      Has.has(obj, 'user.profile.personal.name') === true &&
      Has.has(obj, 'user.profile.personal.age') === true &&
      Has.has(obj, 'user.profile.personal.address') === true &&
      Has.has(obj, 'user.profile.personal.address.city') === true &&
      Has.has(obj, 'user.profile.personal.address.country') === true &&
      Has.has(obj, 'user.profile.preferences') === true &&
      Has.has(obj, 'user.profile.preferences.theme') === true &&
      Has.has(obj, 'user.profile.preferences.language') === true &&
      Has.has(obj, 'user.posts') === true &&
      Has.has(obj, 'user.posts.0') === true &&
      Has.has(obj, 'user.posts.0.title') === true &&
      Has.has(obj, 'user.posts.0.likes') === true &&
      Has.has(obj, 'user.posts.1') === true &&
      Has.has(obj, 'user.posts.1.title') === true &&
      Has.has(obj, 'user.posts.1.likes') === true &&
      Has.has(obj, 'user.posts.2') === false &&
      Has.has(obj, 'user.nonexistent') === false
  })()
)

// 测试数字键存在性检查
console.log(
  "数字键存在性检查:", (() => {
    const obj = { 0: 'zero', 1: 'one', 2: 'two' }

    return Has.has(obj, '0') === true &&
      Has.has(obj, '1') === true &&
      Has.has(obj, '2') === true &&
      Has.has(obj, '3') === false
  })()
)

// 测试特殊字符键存在性检查
console.log(
  "特殊字符键存在性检查:", (() => {
    const obj = { 'key-with-dash': 'value1', 'key.with.dot': 'value2', 'key with space': 'value3' }

    return Has.has(obj, 'key-with-dash') === true &&
      Has.has(obj, 'key.with.dot') === true &&
      Has.has(obj, 'key with space') === true &&
      Has.has(obj, 'key-with-underscore') === false
  })()
)

// 测试布尔值键存在性检查
console.log(
  "布尔值键存在性检查:", (() => {
    const obj = { true: 'yes', false: 'no' }

    return Has.has(obj, 'true') === true &&
      Has.has(obj, 'false') === true
  })()
)

// 测试函数值存在性检查
console.log(
  "函数值存在性检查:", (() => {
    const func = () => 'hello'
    const obj = { method: func }

    return Has.has(obj, 'method') === true
  })()
)

// 测试对象值存在性检查
console.log(
  "对象值存在性检查:", (() => {
    const nested = { value: 'nested' }
    const obj = { nested: nested }

    return Has.has(obj, 'nested') === true &&
      Has.has(obj, 'nested.value') === true &&
      Has.has(obj, 'nested.nonexistent') === false
  })()
)

// 测试数组值存在性检查
console.log(
  "数组值存在性检查:", (() => {
    const arr = [1, 2, 3]
    const obj = { items: arr }

    return Has.has(obj, 'items') === true &&
      Has.has(obj, 'items.0') === true &&
      Has.has(obj, 'items.1') === true &&
      Has.has(obj, 'items.2') === true &&
      Has.has(obj, 'items.3') === false
  })()
)

// 测试null值存在性检查
console.log(
  "null值存在性检查:", (() => {
    const obj = { nullValue: null }

    return Has.has(obj, 'nullValue') === true
  })()
)

// 测试undefined值存在性检查
console.log(
  "undefined值存在性检查:", (() => {
    const obj = { undefinedValue: undefined }

    return Has.has(obj, 'undefinedValue') === true
  })()
)

// 测试空字符串键存在性检查
console.log(
  "空字符串键存在性检查:", (() => {
    const obj = { '': 'empty key' }

    return Has.has(obj, '') === true
  })()
)

// 测试深度路径存在性检查
console.log(
  "深度路径存在性检查:", (() => {
    const obj = { a: { b: { c: { d: { e: 'deep' } } } } }

    return Has.has(obj, 'a') === true &&
      Has.has(obj, 'a.b') === true &&
      Has.has(obj, 'a.b.c') === true &&
      Has.has(obj, 'a.b.c.d') === true &&
      Has.has(obj, 'a.b.c.d.e') === true &&
      Has.has(obj, 'a.b.c.d.e.f') === false
  })()
)

// 测试混合类型路径存在性检查
console.log(
  "混合类型路径存在性检查:", (() => {
    const obj = {
      '0': { '1': { '2': 'value' } },
      'a': { 'b': { 'c': 'another' } }
    }

    return Has.has(obj, '0') === true &&
      Has.has(obj, '0.1') === true &&
      Has.has(obj, '0.1.2') === true &&
      Has.has(obj, 'a') === true &&
      Has.has(obj, 'a.b') === true &&
      Has.has(obj, 'a.b.c') === true &&
      Has.has(obj, '0.1.3') === false &&
      Has.has(obj, 'a.b.d') === false
  })()
)

// 测试原型链属性存在性检查
console.log(
  "原型链属性存在性检查:", (() => {
    function TestClass() {
      this.instanceProp = 'instance'
    }
    TestClass.prototype.prototypeProp = 'prototype'

    const instance = new TestClass()

    return Has.has(instance, 'instanceProp') === true &&
      Has.has(instance, 'prototypeProp') === true &&
      Has.has(instance, 'nonexistentProp') === false
  })()
)

// 测试Symbol键存在性检查
console.log(
  "Symbol键存在性检查:", (() => {
    const sym = Symbol('test')
    const obj = { [sym]: 'symbol value' }

    return Has.has(obj, sym) === true
  })()
)

// 测试复杂数组结构存在性检查
console.log(
  "复杂数组结构存在性检查:", (() => {
    const obj = {
      matrix: [
        [1, 2, 3],
        [4, 5, 6],
        [7, 8, 9]
      ]
    }

    return Has.has(obj, 'matrix') === true &&
      Has.has(obj, 'matrix.0') === true &&
      Has.has(obj, 'matrix.0.0') === true &&
      Has.has(obj, 'matrix.0.1') === true &&
      Has.has(obj, 'matrix.0.2') === true &&
      Has.has(obj, 'matrix.1') === true &&
      Has.has(obj, 'matrix.1.0') === true &&
      Has.has(obj, 'matrix.1.1') === true &&
      Has.has(obj, 'matrix.1.2') === true &&
      Has.has(obj, 'matrix.2') === true &&
      Has.has(obj, 'matrix.2.0') === true &&
      Has.has(obj, 'matrix.2.1') === true &&
      Has.has(obj, 'matrix.2.2') === true &&
      Has.has(obj, 'matrix.3') === false &&
      Has.has(obj, 'matrix.0.3') === false
  })()
)

// 测试边界情况存在性检查
console.log(
  "边界情况存在性检查:", (() => {
    const obj = { a: 1 }

    return Has.has(obj, '') === false &&
      Has.has(obj, ' ') === false &&
      Has.has(obj, 'a ') === false &&
      Has.has(obj, ' a') === false &&
      Has.has(obj, 'a.b.c.d.e.f.g.h') === false
  })()
)

console.log("=== Has 基础测试完成 ===")
